package com.zjitc.controller;

import com.LayuiPageResponse;
import com.github.pagehelper.PageInfo;
import com.zjitc.pojo.City;
import com.zjitc.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created with IDEA
 * author:lhl
 * Date:2019/2/22 0022
 * Time:8:10
 */
@Controller
@RequestMapping(value = "/city")
public class CityController {
    @Autowired
    CityService cityService;
    @RequestMapping(value = "/findAllCityByPage")
    @ResponseBody
    public LayuiPageResponse<City> findAllCity(
            @RequestParam(name = "pageNum",defaultValue = "1",required = true) int pageNum,
            @RequestParam(name = "pageSize",defaultValue = "10",required = false) int pageSize){
        List<City> cities = cityService.findAll(pageNum, pageSize);
        PageInfo info=new PageInfo(cities);
        LayuiPageResponse<City> response=new LayuiPageResponse<>();
        response.setCode(0);
        response.setCount((int)info.getTotal());
        response.setData(cities);
        response.setMsg("");

        return response;
    }
}
